package com.jml.bio;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpServer {

	public static void main(String[] args) throws IOException {
		System.out.println("udp服务器端启动连接....");
		DatagramSocket datagramSocket = new DatagramSocket(8080);
		byte[] bytes = new byte[1024];
		DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
		// 阻塞,等待接受客户端发送请求
		datagramSocket.receive(datagramPacket);
		System.out.println("来源:"+datagramPacket.getAddress()+",端口号:"+datagramPacket.getPort());
		// 获取客户端请求内容
		String str=new String(datagramPacket.getData(),0,datagramPacket.getLength());
		System.out.println("str:"+str);
		datagramSocket.close();
	}


}
